home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / ARPDUMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-01  |  2.0 KB  |  79 lines

  1. /* ARP packet tracing routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "arp.h"
  7. #include "trace.h"
  8.  
  9. #if !defined(_lint)
  10. static char rcsid[] OPTIONAL = "$Id: arpdump.c,v 1.10 1996/09/01 17:09:50 root Exp root $";
  11. #endif
  12.  
  13.  
  14. void
  15. arp_dump (fp, bpp)
  16. FILE *fp;
  17. struct mbuf **bpp;
  18. {
  19. struct arp arp;
  20. struct arp_type *at;
  21. int is_ip = 0;
  22. char tmp[25];
  23.  
  24.     if (bpp == NULLBUFP || *bpp == NULLBUF)
  25.         return;
  26.  
  27.     traceprintf (fp, "ARP: len %d", len_p (*bpp));
  28.     if (ntoharp (&arp, bpp) == -1)    {
  29.         traceprintf (fp, " bad packet\n");
  30.         return;
  31.     }
  32.     if (arp.hardware < NHWTYPES)
  33.         at = &Arp_type[arp.hardware];
  34.     else
  35.         at = NULLATYPE;
  36.  
  37.     /* Print hardware type in Ascii if known, numerically if not */
  38.     traceprintf (fp, " hwtype %s", smsg (Arptypes, NHWTYPES, arp.hardware));
  39.  
  40.     /* Print hardware length only if unknown type, or if it doesn't match
  41.      * the length in the known types table
  42.      */
  43.     if(at == NULLATYPE || (int16) (int) arp.hwalen != at->hwalen)
  44.         traceprintf (fp," hwlen %u", arp.hwalen);
  45.  
  46.     /* Check for most common case -- upper level protocol is IP */
  47.     if (at != NULLATYPE && arp.protocol == at->iptype)    {
  48.         traceprintf (fp, " prot IP");
  49.         is_ip = 1;
  50.     } else
  51.         traceprintf (fp, " prot 0x%x prlen %u", arp.protocol, arp.pralen);
  52.  
  53.     switch (arp.opcode)    {
  54.         case ARP_REQUEST:
  55.             traceprintf (fp, " op REQUEST");
  56.             break;
  57.         case ARP_REPLY:
  58.             traceprintf (fp, " op REPLY");
  59.             break;
  60.         case REVARP_REQUEST:
  61.             traceprintf (fp, " op REVERSE REQUEST");
  62.             break;
  63.         case REVARP_REPLY:
  64.             traceprintf (fp, " op REVERSE REPLY");
  65.             break;
  66.         default:
  67.             traceprintf (fp, " op %u",arp.opcode);
  68.             break;
  69.     }
  70.     traceprintf (fp, "\nsender");
  71.     if (is_ip)
  72.         traceprintf (fp, " IPaddr %s", inet_ntoa (arp.sprotaddr));
  73.     traceprintf (fp, " hwaddr %s\ntarget", (at) ? at->format (tmp, arp.shwaddr) : "??");
  74.     if (is_ip)
  75.         traceprintf (fp, " IPaddr %s", inet_ntoa (arp.tprotaddr));
  76.     traceprintf (fp, " hwaddr %s\n", (at) ? at->format (tmp, arp.thwaddr) : "??");
  77. }
  78.  
  79.